package com.example.demo.mapper;

import com.example.demo.entity.CourseType;
import com.example.demo.entity.CourseTypeCondition;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseTypeMapper {

    @Select("select * from coursetype")
    List<CourseType> selectAll();

    @Select("<script>select * from coursetype where college in " +
            "<foreach collection = 'collegeList' item='college' open='(' separator=',' close=')' > " +
            "#{college}</foreach></script>")
    List<CourseType> selectByCollege(@Param("collegeList") List<String> collegeList);

    @Select("select * from coursetype where id=#{id}")
    CourseType selectById(int id);

    @Select("<script>select * from coursetype where 1=1" +
            "<if test= \"condition.college!='' and condition.college!=null\">and college like concat('%',#{condition.college},'%')</if>" +
            "<if test= \"condition.typeName!='' and condition.typeName!=null\"> and type_name like concat('%',#{condition.typeName},'%')</if></script>")
    List<CourseType> selectByCondition(@Param("condition") CourseTypeCondition condition);

    @Insert("insert into coursetype(college, type_flag, type_name, modify_time) values(#{college},#{typeFlag},#{typeName},now())")
    int add(CourseType courseType);

    @Update("update coursetype set college=#{college},type_flag=#{typeFlag},type_name=#{typeName},modify_time=now() where id=#{id}")
    int update(CourseType courseType);

    @Update("update coursetype set status = 0,modify_time=now() where id=#{id}")
    int delete(int id);
}
